package gy.rpc.client;

import gy.rpc.api.testservice.IUserService;
import gy.rpc.client.structureIntfc.IClientInvocationHandle;
import gy.rpc.client.util.ClientProxyUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @author G_Y
 * 2018年4月22日
 * 代理 服务
 */
public class ProxyInstanceApp {

	/**
	 * 代理接口类 与其代理对象 对应map
	 */
	private static final Map<Class<?>, Object> CLS_PROXY_INSTANCE_MAP = new HashMap<Class<?>, Object>();
	/**
	 * invocation 处理类实例
	 */
	private static final IClientInvocationHandle INVOCATION_HANDLE = ClientInvocationHandle
			.getClientProxy();

	static {
		CLS_PROXY_INSTANCE_MAP.put(IUserService.class, ClientProxyUtil
				.getProxyInstance(IUserService.class, INVOCATION_HANDLE));
	}

	@SuppressWarnings("unchecked")
	public static <T> T getProxyInstanceByClass(Class<T> cls) {
		return (T) CLS_PROXY_INSTANCE_MAP.get(cls);
	}

}
